package com.sgcc.pda.frme.protocol.ws.sendbean;

import android.text.TextUtils;

import com.sgcc.pda.frme.protocol.ws.DataConvert;


/**
 * 载波检测数据
 *
 * @Author: guorongxin
 * @Date: 2016/10/1
 * @Time: 11:31
 */

public class ZaiboCheckParams {

    public static final int SEND_DATA_LENGTH = 28;
    /**
     * 主节点地址 (6字节)
     */
    private String masterNodeAddress;

    /**
     * 从节点地址（6字节）
     */
    private String fromNodeAddress;
    /**
     * 模块类型（1字节）
     * 0：09模块
     * 1：13模块
     */
    private String moduleType;
    /**
     * 表计类型（1字节）
     * 0：97协议
     * 1：07协议
     * 2:13协议
     */
    private String meter_type;
    /**
     * 日期（4字节，格式YYMMDDWW）
     */
    private String date;

    public String getMasterNodeAddress() {
        return masterNodeAddress;
    }

    public void setMasterNodeAddress(String masterNodeAddress) {
        this.masterNodeAddress = masterNodeAddress;
    }

    public String getFromNodeAddress() {
        return fromNodeAddress;
    }

    public void setFromNodeAddress(String fromNodeAddress) {
        this.fromNodeAddress = fromNodeAddress;
    }

    public String getModuleType() {
        return moduleType;
    }

    public void setModuleType(String moduleType) {
        this.moduleType = moduleType;
    }

    public String getMeter_type() {
        return meter_type;
    }

    public void setMeter_type(String meter_type) {
        this.meter_type = meter_type;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    /**
     * 将请求数据转化为byte数组
     *
     * @return 请求数据
     */
    public byte[] fromBytes() {
        return DataConvert.toBytes(toString());
    }


    /**
     * 将请求数据转化为字符串
     *
     * @return 请求数据
     */
    public String toString() {
        StringBuffer result = new StringBuffer();
        if (null == masterNodeAddress || masterNodeAddress.length() != 12) {
            return null;
        }
        result.append(masterNodeAddress);
        if (null == fromNodeAddress || fromNodeAddress.length() != 12) {
            return null;
        }
        result.append(DataConvert.strReverse(fromNodeAddress, 0, fromNodeAddress.length()));
        if (null == moduleType || moduleType.length() != 2) {
            return null;
        }
        result.append(moduleType);
        if (null == meter_type || meter_type.length() != 2) {
            return null;
        }
        result.append(meter_type);
        if (!TextUtils.isEmpty(date)) {
            result.append(DataConvert.strReverse(date, 0, date.length()));
        }
        return result.toString();
    }
}
